home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / pascal / pasc_3.z / pasc_3
Internet Message Format  |  1994-10-24  |  50KB

  1. From steven@cwi.nl Sat Oct  5 20:18:05 1991
  2. Newsgroups: comp.sources.misc
  3. From: steven@cwi.nl (Steven Pemberton)
  4. Subject:  v23i027:  pascal - Public domain Pascal Compiler and Interpreter, Part03/03
  5. Followup-To: comp.sources.d
  6. X-Md4-Signature: 914824487502c49b912d6c64cc68b9ef
  7. Organization: Sterling Software, IMD
  8. Date: Fri, 27 Sep 1991 04:12:35 GMT
  9.  
  10. Submitted-by: steven@cwi.nl (Steven Pemberton)
  11. Posting-number: Volume 23, Issue 27
  12. Archive-name: pascal/part03
  13. Environment: pascal
  14.  
  15. #!/bin/sh
  16. # do not concatenate these parts, unpack them in order with /bin/sh
  17. # file pcom.p continued
  18. #
  19. if test ! -r _shar_seq_.tmp; then
  20.     echo 'Please unpack part 1 first!'
  21.     exit 1
  22. fi
  23. (read Scheck
  24.  if test "$Scheck" != 3; then
  25.     echo Please unpack part "$Scheck" next!
  26.     exit 1
  27.  else
  28.     exit 0
  29.  fi
  30. ) < _shar_seq_.tmp || exit 1
  31. if test ! -f _shar_wnt_.tmp; then
  32.     echo 'x - still skipping pcom.p'
  33. else
  34. echo 'x - continuing file pcom.p'
  35. sed 's/^X//' << 'SHAR_EOF' >> 'pcom.p' &&
  36. X        begin writeln(prr,'l',segsize:4,'=',lcmax);
  37. X          writeln(prr,'l',stacktop:4,'=',topmax);
  38. X          writeln(prr,'q')
  39. X        end;
  40. X      ic := 0;
  41. X      (*generate call of main program; note that this call must be loaded
  42. X        at absolute address zero*)
  43. X      gen1(41(*mst*),0); gencupent(46(*cup*),0,entname); gen0(29(*stp*));
  44. X      if prcode then
  45. X        writeln(prr,'q');
  46. X      saveid := id;
  47. X      while fextfilep <> nil do
  48. X        begin
  49. X          with fextfilep^ do
  50. X        if not ((filename = 'input   ') or (filename = 'output  ') or
  51. X            (filename = 'prd     ') or (filename = 'prr     '))
  52. X        then begin id := filename;
  53. X               searchid([vars],llcp);
  54. X               if llcp^.idtype<>nil then
  55. X             if llcp^.idtype^.form<>files then
  56. X               begin writeln(output);
  57. X                 writeln(output,' ':8,'undeclared ','external ',
  58. X                   'file',fextfilep^.filename:8);
  59. X                 write(output,' ':chcnt+16)
  60. X               end
  61. X             end;
  62. X        fextfilep := fextfilep^.nextfile
  63. X        end;
  64. X      id := saveid;
  65. X      if prtables then
  66. X        begin writeln(output); printtables(true)
  67. X        end
  68. X    end;
  69. X    end (*body*) ;
  70. X
  71. X  begin (*block*)
  72. X    dp := true;
  73. X    repeat
  74. X      if sy = labelsy then
  75. X    begin insymbol; labeldeclaration end;
  76. X      if sy = constsy then
  77. X    begin insymbol; constdeclaration end;
  78. X      if sy = typesy then
  79. X    begin insymbol; typedeclaration end;
  80. X      if sy = varsy then
  81. X    begin insymbol; vardeclaration end;
  82. X      while sy in [procsy,funcsy] do
  83. X    begin lsy := sy; insymbol; procdeclaration(lsy) end;
  84. X      if sy <> beginsy then
  85. X    begin error(18); skip(fsys) end
  86. X    until (sy in statbegsys) or eof(input);
  87. X    dp := false;
  88. X    if sy = beginsy then insymbol else error(17);
  89. X    repeat body(fsys + [casesy]);
  90. X      if sy <> fsy then
  91. X    begin error(6); skip(fsys) end
  92. X    until ((sy = fsy) or (sy in blockbegsys)) or eof(input);
  93. X  end (*block*) ;
  94. X
  95. X  procedure programme(fsys:setofsys);
  96. X    var extfp:extfilep;
  97. X  begin
  98. X    if sy = progsy then
  99. X      begin insymbol; if sy <> ident then error(2); insymbol;
  100. X    if not (sy in [lparent,semicolon]) then error(14);
  101. X    if sy = lparent  then
  102. X      begin
  103. X        repeat insymbol;
  104. X          if sy = ident then
  105. X        begin new(extfp);
  106. X          with extfp^ do
  107. X            begin filename := id; nextfile := fextfilep end;
  108. X          fextfilep := extfp;
  109. X          insymbol;
  110. X          if not ( sy in [comma,rparent] ) then error(20)
  111. X        end
  112. X          else error(2)
  113. X        until sy <> comma;
  114. X        if sy <> rparent then error(4);
  115. X        insymbol
  116. X      end;
  117. X    if sy <> semicolon then error(14)
  118. X    else insymbol;
  119. X      end;
  120. X    repeat block(fsys,period,nil);
  121. X      if sy <> period then error(21)
  122. X    until (sy = period) or eof(input);
  123. X    if list then writeln(output);
  124. X    if errinx <> 0 then
  125. X      begin list := false; endofline end
  126. X  end (*programme*) ;
  127. X
  128. X
  129. X  procedure stdnames;
  130. X  begin
  131. X    na[ 1] := 'false   '; na[ 2] := 'true    '; na[ 3] := 'input   ';
  132. X    na[ 4] := 'output  '; na[ 5] := 'get     '; na[ 6] := 'put     ';
  133. X    na[ 7] := 'reset   '; na[ 8] := 'rewrite '; na[ 9] := 'read    ';
  134. X    na[10] := 'write   '; na[11] := 'pack    '; na[12] := 'unpack  ';
  135. X    na[13] := 'new     '; na[14] := 'release '; na[15] := 'readln  ';
  136. X    na[16] := 'writeln ';
  137. X    na[17] := 'abs     '; na[18] := 'sqr     '; na[19] := 'trunc   ';
  138. X    na[20] := 'odd     '; na[21] := 'ord     '; na[22] := 'chr     ';
  139. X    na[23] := 'pred    '; na[24] := 'succ    '; na[25] := 'eof     ';
  140. X    na[26] := 'eoln    ';
  141. X    na[27] := 'sin     '; na[28] := 'cos     '; na[29] := 'exp     ';
  142. X    na[30] := 'sqrt    '; na[31] := 'ln      '; na[32] := 'arctan  ';
  143. X    na[33] := 'prd     '; na[34] := 'prr     '; na[35] := 'mark    ';
  144. X  end (*stdnames*) ;
  145. X
  146. X  procedure enterstdtypes;
  147. X
  148. X  begin                         (*type underlying:*)
  149. X                            (******************)
  150. X
  151. X    new(intptr,scalar,standard);                  (*integer*)
  152. X    with intptr^ do
  153. X      begin size := intsize; form := scalar; scalkind := standard end;
  154. X    new(realptr,scalar,standard);                 (*real*)
  155. X    with realptr^ do
  156. X      begin size := realsize; form := scalar; scalkind := standard end;
  157. X    new(charptr,scalar,standard);                 (*char*)
  158. X    with charptr^ do
  159. X      begin size := charsize; form := scalar; scalkind := standard end;
  160. X    new(boolptr,scalar,declared);                 (*boolean*)
  161. X    with boolptr^ do
  162. X      begin size := boolsize; form := scalar; scalkind := declared end;
  163. X    new(nilptr,pointer);                      (*nil*)
  164. X    with nilptr^ do
  165. X      begin eltype := nil; size := ptrsize; form := pointer end;
  166. X    new(parmptr,scalar,standard); (*for alignment of parameters*)
  167. X    with parmptr^ do
  168. X      begin size := parmsize; form := scalar; scalkind := standard end ;
  169. X    new(textptr,files);                       (*text*)
  170. X    with textptr^ do
  171. X      begin filtype := charptr; size := charsize; form := files end
  172. X  end (*enterstdtypes*) ;
  173. X
  174. X  procedure entstdnames;
  175. X    var cp,cp1: ctp; i: integer;
  176. X  begin                               (*name:*)
  177. X                                  (*******)
  178. X
  179. X    new(cp,types);                        (*integer*)
  180. X    with cp^ do
  181. X      begin name := 'integer '; idtype := intptr; klass := types end;
  182. X    enterid(cp);
  183. X    new(cp,types);                        (*real*)
  184. X    with cp^ do
  185. X      begin name := 'real    '; idtype := realptr; klass := types end;
  186. X    enterid(cp);
  187. X    new(cp,types);                        (*char*)
  188. X    with cp^ do
  189. X      begin name := 'char    '; idtype := charptr; klass := types end;
  190. X    enterid(cp);
  191. X    new(cp,types);                        (*boolean*)
  192. X    with cp^ do
  193. X      begin name := 'boolean '; idtype := boolptr; klass := types end;
  194. X    enterid(cp);
  195. X    cp1 := nil;
  196. X    for i := 1 to 2 do
  197. X      begin new(cp,konst);                    (*false,true*)
  198. X    with cp^ do
  199. X      begin name := na[i]; idtype := boolptr;
  200. X        next := cp1; values.ival := i - 1; klass := konst
  201. X      end;
  202. X    enterid(cp); cp1 := cp
  203. X      end;
  204. X    boolptr^.fconst := cp;
  205. X    new(cp,konst);                        (*nil*)
  206. X    with cp^ do
  207. X      begin name := 'nil     '; idtype := nilptr;
  208. X    next := nil; values.ival := 0; klass := konst
  209. X      end;
  210. X    enterid(cp);
  211. X    for i := 3 to 4 do
  212. X      begin new(cp,vars);                     (*input,output*)
  213. X    with cp^ do
  214. X      begin name := na[i]; idtype := textptr; klass := vars;
  215. X        vkind := actual; next := nil; vlev := 1;
  216. X        vaddr := lcaftermarkstack+(i-3)*charmax;
  217. X      end;
  218. X    enterid(cp)
  219. X      end;
  220. X    for i:=33 to 34 do
  221. X      begin new(cp,vars);                     (*prd,prr files*)
  222. X     with cp^ do
  223. X       begin name := na[i]; idtype := textptr; klass := vars;
  224. X          vkind := actual; next := nil; vlev := 1;
  225. X          vaddr := lcaftermarkstack+(i-31)*charmax;
  226. X       end;
  227. X     enterid(cp)
  228. X      end;
  229. X    for i := 5 to 16 do
  230. X      begin new(cp,proc,standard);                (*get,put,reset*)
  231. X    with cp^ do                       (*rewrite,read*)
  232. X      begin name := na[i]; idtype := nil;         (*write,pack*)
  233. X        next := nil; key := i - 4;            (*unpack,pack*)
  234. X        klass := proc; pfdeckind := standard
  235. X      end;
  236. X    enterid(cp)
  237. X      end;
  238. X    new(cp,proc,standard);
  239. X    with cp^ do
  240. X      begin name:=na[35]; idtype:=nil;
  241. X        next:= nil; key:=13;
  242. X        klass:=proc; pfdeckind:= standard
  243. X      end; enterid(cp);
  244. X    for i := 17 to 26 do
  245. X      begin new(cp,func,standard);                (*abs,sqr,trunc*)
  246. X    with cp^ do                       (*odd,ord,chr*)
  247. X      begin name := na[i]; idtype := nil;         (*pred,succ,eof*)
  248. X        next := nil; key := i - 16;
  249. X        klass := func; pfdeckind := standard
  250. X      end;
  251. X    enterid(cp)
  252. X      end;
  253. X    new(cp,vars);              (*parameter of predeclared functions*)
  254. X    with cp^ do
  255. X      begin name := '        '; idtype := realptr; klass := vars;
  256. X    vkind := actual; next := nil; vlev := 1; vaddr := 0
  257. X      end;
  258. X    for i := 27 to 32 do
  259. X      begin new(cp1,func,declared,actual);            (*sin,cos,exp*)
  260. X    with cp1^ do                      (*sqrt,ln,arctan*)
  261. X      begin name := na[i]; idtype := realptr; next := cp;
  262. X        forwdecl := false; extern := true; pflev := 0; pfname := i - 12;
  263. X        klass := func; pfdeckind := declared; pfkind := actual
  264. X      end;
  265. X    enterid(cp1)
  266. X      end
  267. X  end (*entstdnames*) ;
  268. X
  269. X  procedure enterundecl;
  270. X  begin
  271. X    new(utypptr,types);
  272. X    with utypptr^ do
  273. X      begin name := '        '; idtype := nil; klass := types end;
  274. X    new(ucstptr,konst);
  275. X    with ucstptr^ do
  276. X      begin name := '        '; idtype := nil; next := nil;
  277. X    values.ival := 0; klass := konst
  278. X      end;
  279. X    new(uvarptr,vars);
  280. X    with uvarptr^ do
  281. X      begin name := '        '; idtype := nil; vkind := actual;
  282. X    next := nil; vlev := 0; vaddr := 0; klass := vars
  283. X      end;
  284. X    new(ufldptr,field);
  285. X    with ufldptr^ do
  286. X      begin name := '        '; idtype := nil; next := nil; fldaddr := 0;
  287. X    klass := field
  288. X      end;
  289. X    new(uprcptr,proc,declared,actual);
  290. X    with uprcptr^ do
  291. X      begin name := '        '; idtype := nil; forwdecl := false;
  292. X    next := nil; extern := false; pflev := 0; genlabel(pfname);
  293. X    klass := proc; pfdeckind := declared; pfkind := actual
  294. X      end;
  295. X    new(ufctptr,func,declared,actual);
  296. X    with ufctptr^ do
  297. X      begin name := '        '; idtype := nil; next := nil;
  298. X    forwdecl := false; extern := false; pflev := 0; genlabel(pfname);
  299. X    klass := func; pfdeckind := declared; pfkind := actual
  300. X      end
  301. X  end (*enterundecl*) ;
  302. X
  303. X  procedure initscalars;
  304. X  begin fwptr := nil;
  305. X    prtables := false; list := true; prcode := true; debug := true;
  306. X    dp := true; prterr := true; errinx := 0;
  307. X    intlabel := 0; kk := 8; fextfilep := nil;
  308. X    lc := lcaftermarkstack+filebuffer*charmax;
  309. X    (* note in the above reservation of buffer store for 2 text files *)
  310. X    ic := 3; eol := true; linecount := 0;
  311. X    ch := ' '; chcnt := 0;
  312. X    globtestp := nil;
  313. X    mxint10 := maxint div 10; digmax := strglgth - 1;
  314. X  end (*initscalars*) ;
  315. X
  316. X  procedure initsets;
  317. X  begin
  318. X    constbegsys := [addop,intconst,realconst,stringconst,ident];
  319. X    simptypebegsys := [lparent] + constbegsys;
  320. X    typebegsys:=[arrow,packedsy,arraysy,recordsy,setsy,filesy]+simptypebegsys;
  321. X    typedels := [arraysy,recordsy,setsy,filesy];
  322. X    blockbegsys := [labelsy,constsy,typesy,varsy,procsy,funcsy,beginsy];
  323. X    selectsys := [arrow,period,lbrack];
  324. X    facbegsys := [intconst,realconst,stringconst,ident,lparent,lbrack,notsy];
  325. X    statbegsys := [beginsy,gotosy,ifsy,whilesy,repeatsy,forsy,withsy,casesy];
  326. X  end (*initsets*) ;
  327. X
  328. X  procedure inittables;
  329. X    procedure reswords;
  330. X    begin
  331. X      rw[ 1] := 'if      '; rw[ 2] := 'do      '; rw[ 3] := 'of      ';
  332. X      rw[ 4] := 'to      '; rw[ 5] := 'in      '; rw[ 6] := 'or      ';
  333. X      rw[ 7] := 'end     '; rw[ 8] := 'for     '; rw[ 9] := 'var     ';
  334. X      rw[10] := 'div     '; rw[11] := 'mod     '; rw[12] := 'set     ';
  335. X      rw[13] := 'and     '; rw[14] := 'not     '; rw[15] := 'then    ';
  336. X      rw[16] := 'else    '; rw[17] := 'with    '; rw[18] := 'goto    ';
  337. X      rw[19] := 'case    '; rw[20] := 'type    ';
  338. X      rw[21] := 'file    '; rw[22] := 'begin   ';
  339. X      rw[23] := 'until   '; rw[24] := 'while   '; rw[25] := 'array   ';
  340. X      rw[26] := 'const   '; rw[27] := 'label   ';
  341. X      rw[28] := 'repeat  '; rw[29] := 'record  '; rw[30] := 'downto  ';
  342. X      rw[31] := 'packed  '; rw[32] := 'forward '; rw[33] := 'program ';
  343. X      rw[34] := 'function'; rw[35] := 'procedur';
  344. X      frw[1] :=  1; frw[2] :=  1; frw[3] :=  7; frw[4] := 15; frw[5] := 22;
  345. X      frw[6] := 28; frw[7] := 32; frw[8] := 34; frw[9] := 36;
  346. X    end (*reswords*) ;
  347. X
  348. X    procedure symbols;
  349. X    begin
  350. X      rsy[ 1] := ifsy;      rsy[ 2] := dosy;      rsy[ 3] := ofsy;
  351. X      rsy[ 4] := tosy;      rsy[ 5] := relop;     rsy[ 6] := addop;
  352. X      rsy[ 7] := endsy;     rsy[ 8] := forsy;     rsy[ 9] := varsy;
  353. X      rsy[10] := mulop;     rsy[11] := mulop;     rsy[12] := setsy;
  354. X      rsy[13] := mulop;     rsy[14] := notsy;     rsy[15] := thensy;
  355. X      rsy[16] := elsesy;    rsy[17] := withsy;    rsy[18] := gotosy;
  356. X      rsy[19] := casesy;    rsy[20] := typesy;
  357. X      rsy[21] := filesy;    rsy[22] := beginsy;
  358. X      rsy[23] := untilsy;   rsy[24] := whilesy;   rsy[25] := arraysy;
  359. X      rsy[26] := constsy;   rsy[27] := labelsy;
  360. X      rsy[28] := repeatsy;  rsy[29] := recordsy;  rsy[30] := downtosy;
  361. X      rsy[31] := packedsy;  rsy[32] := forwardsy; rsy[33] := progsy;
  362. X      rsy[34] := funcsy;    rsy[35] := procsy;
  363. X      ssy['+'] := addop ;   ssy['-'] := addop;    ssy['*'] := mulop;
  364. X      ssy['/'] := mulop ;   ssy['('] := lparent;  ssy[')'] := rparent;
  365. X      ssy['$'] := othersy ; ssy['='] := relop;    ssy[' '] := othersy;
  366. X      ssy[','] := comma ;   ssy['.'] := period;   ssy['''']:= othersy;
  367. X      ssy['['] := lbrack ;  ssy[']'] := rbrack;   ssy[':'] := colon;
  368. X      ssy['^'] := arrow ;   ssy['<'] := relop;    ssy['>'] := relop;
  369. X      ssy[';'] := semicolon;
  370. X    end (*symbols*) ;
  371. X
  372. X    procedure rators;
  373. X      var i: integer;
  374. X    begin
  375. X      for i := 1 to 35 (*nr of res words*) do rop[i] := noop;
  376. X      rop[5] := inop; rop[10] := idiv; rop[11] := imod;
  377. X      rop[6] := orop; rop[13] := andop;
  378. X      for i := ordminchar to ordmaxchar do sop[chr(i)] := noop;
  379. X      sop['+'] := plus; sop['-'] := minus; sop['*'] := mul; sop['/'] := rdiv;
  380. X      sop['='] := eqop; sop['<'] := ltop;  sop['>'] := gtop;
  381. X    end (*rators*) ;
  382. X
  383. X    procedure procmnemonics;
  384. X    begin
  385. X      sna[ 1] :=' get'; sna[ 2] :=' put'; sna[ 3] :=' rdi'; sna[ 4] :=' rdr';
  386. X      sna[ 5] :=' rdc'; sna[ 6] :=' wri'; sna[ 7] :=' wro'; sna[ 8] :=' wrr';
  387. X      sna[ 9] :=' wrc'; sna[10] :=' wrs'; sna[11] :=' pak'; sna[12] :=' new';
  388. X      sna[13] :=' rst'; sna[14] :=' eln'; sna[15] :=' sin'; sna[16] :=' cos';
  389. X      sna[17] :=' exp'; sna[18] :=' sqt'; sna[19] :=' log'; sna[20] :=' atn';
  390. X      sna[21] :=' rln'; sna[22] :=' wln'; sna[23] :=' sav';
  391. X    end (*procmnemonics*) ;
  392. X
  393. X    procedure instrmnemonics;
  394. X    begin
  395. X      mn[ 0] :=' abi'; mn[ 1] :=' abr'; mn[ 2] :=' adi'; mn[ 3] :=' adr';
  396. X      mn[ 4] :=' and'; mn[ 5] :=' dif'; mn[ 6] :=' dvi'; mn[ 7] :=' dvr';
  397. X      mn[ 8] :=' eof'; mn[ 9] :=' flo'; mn[10] :=' flt'; mn[11] :=' inn';
  398. X      mn[12] :=' int'; mn[13] :=' ior'; mn[14] :=' mod'; mn[15] :=' mpi';
  399. X      mn[16] :=' mpr'; mn[17] :=' ngi'; mn[18] :=' ngr'; mn[19] :=' not';
  400. X      mn[20] :=' odd'; mn[21] :=' sbi'; mn[22] :=' sbr'; mn[23] :=' sgs';
  401. X      mn[24] :=' sqi'; mn[25] :=' sqr'; mn[26] :=' sto'; mn[27] :=' trc';
  402. X      mn[28] :=' uni'; mn[29] :=' stp'; mn[30] :=' csp'; mn[31] :=' dec';
  403. X      mn[32] :=' ent'; mn[33] :=' fjp'; mn[34] :=' inc'; mn[35] :=' ind';
  404. X      mn[36] :=' ixa'; mn[37] :=' lao'; mn[38] :=' lca'; mn[39] :=' ldo';
  405. X      mn[40] :=' mov'; mn[41] :=' mst'; mn[42] :=' ret'; mn[43] :=' sro';
  406. X      mn[44] :=' xjp'; mn[45] :=' chk'; mn[46] :=' cup'; mn[47] :=' equ';
  407. X      mn[48] :=' geq'; mn[49] :=' grt'; mn[50] :=' lda'; mn[51] :=' ldc';
  408. X      mn[52] :=' leq'; mn[53] :=' les'; mn[54] :=' lod'; mn[55] :=' neq';
  409. X      mn[56] :=' str'; mn[57] :=' ujp'; mn[58] :=' ord'; mn[59] :=' chr';
  410. X      mn[60] :=' ujc';
  411. X    end (*instrmnemonics*) ;
  412. X
  413. X    procedure chartypes;
  414. X    var i : integer;
  415. X    begin
  416. X      for i := ordminchar to ordmaxchar do chartp[chr(i)] := illegal;
  417. X      chartp['a'] := letter  ;
  418. X      chartp['b'] := letter  ; chartp['c'] := letter  ;
  419. X      chartp['d'] := letter  ; chartp['e'] := letter  ;
  420. X      chartp['f'] := letter  ; chartp['g'] := letter  ;
  421. X      chartp['h'] := letter  ; chartp['i'] := letter  ;
  422. X      chartp['j'] := letter  ; chartp['k'] := letter  ;
  423. X      chartp['l'] := letter  ; chartp['m'] := letter  ;
  424. X      chartp['n'] := letter  ; chartp['o'] := letter  ;
  425. X      chartp['p'] := letter  ; chartp['q'] := letter  ;
  426. X      chartp['r'] := letter  ; chartp['s'] := letter  ;
  427. X      chartp['t'] := letter  ; chartp['u'] := letter  ;
  428. X      chartp['v'] := letter  ; chartp['w'] := letter  ;
  429. X      chartp['x'] := letter  ; chartp['y'] := letter  ;
  430. X      chartp['z'] := letter  ; chartp['0'] := number  ;
  431. X      chartp['1'] := number  ; chartp['2'] := number  ;
  432. X      chartp['3'] := number  ; chartp['4'] := number  ;
  433. X      chartp['5'] := number  ; chartp['6'] := number  ;
  434. X      chartp['7'] := number  ; chartp['8'] := number  ;
  435. X      chartp['9'] := number  ; chartp['+'] := special ;
  436. X      chartp['-'] := special ; chartp['*'] := special ;
  437. X      chartp['/'] := special ; chartp['('] := chlparen;
  438. X      chartp[')'] := special ; chartp['$'] := special ;
  439. X      chartp['='] := special ; chartp[' '] := chspace ;
  440. X      chartp[','] := special ; chartp['.'] := chperiod;
  441. X      chartp['''']:= chstrquo; chartp['['] := special ;
  442. X      chartp[']'] := special ; chartp[':'] := chcolon ;
  443. X      chartp['^'] := special ; chartp[';'] := special ;
  444. X      chartp['<'] := chlt    ; chartp['>'] := chgt    ;
  445. X      ordint['0'] := 0; ordint['1'] := 1; ordint['2'] := 2;
  446. X      ordint['3'] := 3; ordint['4'] := 4; ordint['5'] := 5;
  447. X      ordint['6'] := 6; ordint['7'] := 7; ordint['8'] := 8;
  448. X      ordint['9'] := 9;
  449. X    end;
  450. X
  451. X    procedure initdx;
  452. X    begin
  453. X      cdx[ 0] :=  0; cdx[ 1] :=  0; cdx[ 2] := -1; cdx[ 3] := -1;
  454. X      cdx[ 4] := -1; cdx[ 5] := -1; cdx[ 6] := -1; cdx[ 7] := -1;
  455. X      cdx[ 8] :=  0; cdx[ 9] :=  0; cdx[10] :=  0; cdx[11] := -1;
  456. X      cdx[12] := -1; cdx[13] := -1; cdx[14] := -1; cdx[15] := -1;
  457. X      cdx[16] := -1; cdx[17] :=  0; cdx[18] :=  0; cdx[19] :=  0;
  458. X      cdx[20] :=  0; cdx[21] := -1; cdx[22] := -1; cdx[23] :=  0;
  459. X      cdx[24] :=  0; cdx[25] :=  0; cdx[26] := -2; cdx[27] :=  0;
  460. X      cdx[28] := -1; cdx[29] :=  0; cdx[30] :=  0; cdx[31] :=  0;
  461. X      cdx[32] :=  0; cdx[33] := -1; cdx[34] :=  0; cdx[35] :=  0;
  462. X      cdx[36] := -1; cdx[37] := +1; cdx[38] := +1; cdx[39] := +1;
  463. X      cdx[40] := -2; cdx[41] :=  0; cdx[42] :=  0; cdx[43] := -1;
  464. X      cdx[44] := -1; cdx[45] :=  0; cdx[46] :=  0; cdx[47] := -1;
  465. X      cdx[48] := -1; cdx[49] := -1; cdx[50] := +1; cdx[51] := +1;
  466. X      cdx[52] := -1; cdx[53] := -1; cdx[54] := +1; cdx[55] := -1;
  467. X      cdx[56] := -1; cdx[57] :=  0; cdx[58] :=  0; cdx[59] :=  0;
  468. X      cdx[60] :=  0;
  469. X      pdx[ 1] := -1; pdx[ 2] := -1; pdx[ 3] := -2; pdx[ 4] := -2;
  470. X      pdx[ 5] := -2; pdx[ 6] := -3; pdx[ 7] := -3; pdx[ 8] := -3;
  471. X      pdx[ 9] := -3; pdx[10] := -4; pdx[11] :=  0; pdx[12] := -2;
  472. X      pdx[13] := -1; pdx[14] :=  0; pdx[15] :=  0; pdx[16] :=  0;
  473. X      pdx[17] :=  0; pdx[18] :=  0; pdx[19] :=  0; pdx[20] :=  0;
  474. X      pdx[21] := -1; pdx[22] := -1; pdx[23] := -1;
  475. X    end;
  476. X
  477. X  begin (*inittables*)
  478. X    reswords; symbols; rators;
  479. X    instrmnemonics; procmnemonics;
  480. X    chartypes; initdx;
  481. X  end (*inittables*) ;
  482. X
  483. begin
  484. X  (*initialize*)
  485. X  (************)
  486. X  initscalars; initsets; inittables;
  487. X
  488. X
  489. X  (*enter standard names and standard types:*)
  490. X  (******************************************)
  491. X  level := 0; top := 0;
  492. X  with display[0] do
  493. X    begin fname := nil; flabel := nil; occur := blck end;
  494. X  enterstdtypes;   stdnames; entstdnames;   enterundecl;
  495. X  top := 1; level := 1;
  496. X  with display[1] do
  497. X    begin fname := nil; flabel := nil; occur := blck end;
  498. X
  499. X
  500. X  (*compile:*) (*rewrite(prr); (*comment this out when compiling with pcom *)
  501. X  (**********)
  502. X  insymbol;
  503. X  programme(blockbegsys+statbegsys-[casesy]);
  504. X
  505. end.
  506. SHAR_EOF
  507. echo 'File pcom.p is complete' &&
  508. chmod 0644 pcom.p ||
  509. echo 'restore of pcom.p failed'
  510. Wc_c="`wc -c < 'pcom.p'`"
  511. test 117626 -eq "$Wc_c" ||
  512.     echo 'pcom.p: original size 117626, current size' "$Wc_c"
  513. rm -f _shar_wnt_.tmp
  514. fi
  515. # ============= pint.p ==============
  516. if test -f 'pint.p' -a X"$1" != X"-c"; then
  517.     echo 'x - skipping pint.p (File already exists)'
  518.     rm -f _shar_wnt_.tmp
  519. else
  520. > _shar_wnt_.tmp
  521. echo 'x - extracting pint.p (Text)'
  522. sed 's/^X//' << 'SHAR_EOF' > 'pint.p' &&
  523. (*Assembler and interpreter of Pascal code*)
  524. (*K. Jensen, N. Wirth, Ch. Jacobi, ETH May 76*)
  525. X
  526. program pcode(input,output,prd,prr);
  527. X
  528. (* Note for the implementation.
  529. X   ===========================
  530. This interpreter is written for the case where all the fundamental types
  531. take one storage unit.
  532. In an actual implementation, the handling of the sp pointer has to take
  533. into account the fact that the types may have lengths different from one:
  534. in push and pop operations the sp has to be increased and decreased not
  535. by 1, but by a number depending on the type concerned.
  536. However, where the number of units of storage has been computed by the
  537. compiler, the value must not be corrected, since the lengths of the types
  538. involved have already been taken into account.
  539. X                                 *)
  540. X
  541. X
  542. X
  543. X
  544. label 1;
  545. const codemax     = 8650;
  546. X      pcmax       = 17500;
  547. X      maxstk      = 13650; (* size of variable store *)
  548. X      overi       = 13655; (* size of integer constant table = 5 *)
  549. X      overr       = 13660; (* size of real constant table = 5 *)
  550. X      overs       = 13730; (* size of set constant table = 70 *)
  551. X      overb       = 13820;
  552. X      overm       = 18000;
  553. X      maxstr      = 18001;
  554. X      largeint    = 26144;
  555. X      begincode   = 3;
  556. X      inputadr    = 5;
  557. X      outputadr   = 6;
  558. X      prdadr      = 7;
  559. X      prradr      = 8;
  560. X      duminst     = 62;
  561. X
  562. type  bit4    = 0..15;
  563. X      bit6    = 0..127;
  564. X      bit20       = -26143..26143;
  565. X      datatype    = (undef,int,reel,bool,sett,adr,mark,car);
  566. X      address     = -1..maxstr;
  567. X      beta    = packed array[1..25] of char; (*error message*)
  568. X      settype     = set of 0..58;
  569. X
  570. var   code    : array[0..codemax] of   (* the program *)
  571. X              packed record  op1    :bit6;
  572. X                     p1     :bit4;
  573. X                     q1     :bit20;
  574. X                     op2    :bit6;
  575. X                     p2     :bit4;
  576. X                     q2     :bit20
  577. X                 end;
  578. X      pc       : 0..pcmax;     (*program address register*)
  579. X      op : bit6; p : bit4; q : bit20;  (*instruction register*)
  580. X
  581. X      store    : array [0..overm] of
  582. X               record case datatype of
  583. X                int    :(vi :integer);
  584. X                reel       :(vr :real);
  585. X                bool       :(vb :boolean);
  586. X                sett       :(vs :settype);
  587. X                car    :(vc :char);
  588. X                adr    :(va :address);
  589. X                         (*address in store*)
  590. X                mark       :(vm :integer)
  591. X            end;
  592. X       mp,sp,np,ep : address;  (* address registers *)
  593. X       (*mp  points to beginning of a data segment
  594. X     sp  points to top of the stack
  595. X     ep  points to the maximum extent of the stack
  596. X     np  points to top of the dynamically allocated area*)
  597. X
  598. X       interpreting: boolean;
  599. X       prd,prr     : text;(*prd for read only, prr for write only *)
  600. X
  601. X       instr       : array[bit6] of alfa; (* mnemonic instruction codes *)
  602. X       cop     : array[bit6] of integer;
  603. X       sptable     : array[0..20] of alfa; (*standard functions and procedures*)
  604. X
  605. X      (*locally used for interpreting one instruction*)
  606. X       ad,ad1      : address;
  607. X       b       : boolean;
  608. X       i,j,i1,i2   : integer;
  609. X       c       : char;
  610. X
  611. (*--------------------------------------------------------------------*)
  612. X
  613. procedure load;
  614. X   const maxlabel = 1850;
  615. X   type  labelst  = (entered,defined); (*label situation*)
  616. X     labelrg  = 0..maxlabel;       (*label range*)
  617. X     labelrec = record
  618. X              val: address;
  619. X               st: labelst
  620. X            end;
  621. X   var  icp,rcp,scp,bcp,mcp  : address;  (*pointers to next free position*)
  622. X    word : array[1..10] of char; i  : integer;  ch  : char;
  623. X    labeltab: array[labelrg] of labelrec;
  624. X    labelvalue: address;
  625. X
  626. X   procedure init;
  627. X      var i: integer;
  628. X   begin instr[ 0]:='lod       ';       instr[ 1]:='ldo       ';
  629. X     instr[ 2]:='str       ';       instr[ 3]:='sro       ';
  630. X     instr[ 4]:='lda       ';       instr[ 5]:='lao       ';
  631. X     instr[ 6]:='sto       ';       instr[ 7]:='ldc       ';
  632. X     instr[ 8]:='...       ';       instr[ 9]:='ind       ';
  633. X     instr[10]:='inc       ';       instr[11]:='mst       ';
  634. X     instr[12]:='cup       ';       instr[13]:='ent       ';
  635. X     instr[14]:='ret       ';       instr[15]:='csp       ';
  636. X     instr[16]:='ixa       ';       instr[17]:='equ       ';
  637. X     instr[18]:='neq       ';       instr[19]:='geq       ';
  638. X     instr[20]:='grt       ';       instr[21]:='leq       ';
  639. X     instr[22]:='les       ';       instr[23]:='ujp       ';
  640. X     instr[24]:='fjp       ';       instr[25]:='xjp       ';
  641. X     instr[26]:='chk       ';       instr[27]:='eof       ';
  642. X     instr[28]:='adi       ';       instr[29]:='adr       ';
  643. X     instr[30]:='sbi       ';       instr[31]:='sbr       ';
  644. X     instr[32]:='sgs       ';       instr[33]:='flt       ';
  645. X     instr[34]:='flo       ';       instr[35]:='trc       ';
  646. X     instr[36]:='ngi       ';       instr[37]:='ngr       ';
  647. X     instr[38]:='sqi       ';       instr[39]:='sqr       ';
  648. X     instr[40]:='abi       ';       instr[41]:='abr       ';
  649. X     instr[42]:='not       ';       instr[43]:='and       ';
  650. X     instr[44]:='ior       ';       instr[45]:='dif       ';
  651. X     instr[46]:='int       ';       instr[47]:='uni       ';
  652. X     instr[48]:='inn       ';       instr[49]:='mod       ';
  653. X     instr[50]:='odd       ';       instr[51]:='mpi       ';
  654. X     instr[52]:='mpr       ';       instr[53]:='dvi       ';
  655. X     instr[54]:='dvr       ';       instr[55]:='mov       ';
  656. X     instr[56]:='lca       ';       instr[57]:='dec       ';
  657. X     instr[58]:='stp       ';       instr[59]:='ord       ';
  658. X     instr[60]:='chr       ';       instr[61]:='ujc       ';
  659. X
  660. X     sptable[ 0]:='get       ';     sptable[ 1]:='put       ';
  661. X     sptable[ 2]:='rst       ';     sptable[ 3]:='rln       ';
  662. X     sptable[ 4]:='new       ';     sptable[ 5]:='wln       ';
  663. X     sptable[ 6]:='wrs       ';     sptable[ 7]:='eln       ';
  664. X     sptable[ 8]:='wri       ';     sptable[ 9]:='wrr       ';
  665. X     sptable[10]:='wrc       ';     sptable[11]:='rdi       ';
  666. X     sptable[12]:='rdr       ';     sptable[13]:='rdc       ';
  667. X     sptable[14]:='sin       ';     sptable[15]:='cos       ';
  668. X     sptable[16]:='exp       ';     sptable[17]:='log       ';
  669. X     sptable[18]:='sqt       ';     sptable[19]:='atn       ';
  670. X     sptable[20]:='sav       ';
  671. X
  672. X     cop[ 0] := 105;  cop[ 1] :=  65;
  673. X     cop[ 2] :=  70;  cop[ 3] :=  75;
  674. X     cop[ 6] :=  80;  cop[ 9] :=  85;
  675. X     cop[10] :=  90;  cop[26] :=  95;
  676. X     cop[57] := 100;
  677. X
  678. X     pc  := begincode;
  679. X     icp := maxstk + 1;
  680. X     rcp := overi + 1;
  681. X     scp := overr + 1;
  682. X     bcp := overs + 2;
  683. X     mcp := overb + 1;
  684. X     for i:= 1 to 10 do word[i]:= ' ';
  685. X     for i:= 0 to maxlabel do
  686. X         with labeltab[i] do begin val:=-1; st:= entered end;
  687. X     reset(prd);
  688. X   end;(*init*)
  689. X
  690. X   procedure errorl(string: beta); (*error in loading*)
  691. X   begin writeln;
  692. X      write(string);
  693. X      halt
  694. X   end; (*errorl*)
  695. X
  696. X   procedure update(x: labelrg); (*when a label definition lx is found*)
  697. X      var curr,succ: -1..pcmax;  (*resp. current element and successor element
  698. X                   of a list of future references*)
  699. X      endlist: boolean;
  700. X   begin
  701. X      if labeltab[x].st=defined then errorl(' duplicated label    ')
  702. X      else begin
  703. X         if labeltab[x].val<>-1 then (*forward reference(s)*)
  704. X         begin curr:= labeltab[x].val; endlist:= false;
  705. X        while not endlist do
  706. X              with code[curr div 2] do
  707. X              begin
  708. X             if odd(curr) then begin succ:= q2;
  709. X                         q2:= labelvalue
  710. X                       end
  711. X                      else begin succ:= q1;
  712. X                         q1:= labelvalue
  713. X                       end;
  714. X             if succ=-1 then endlist:= true
  715. X                    else curr:= succ
  716. X              end;
  717. X          end;
  718. X          labeltab[x].st := defined;
  719. X          labeltab[x].val:= labelvalue;
  720. X       end
  721. X   end;(*update*)
  722. X
  723. X   procedure assemble; forward;
  724. X
  725. X   procedure generate;(*generate segment of code*)
  726. X      var x: integer; (* label number *)
  727. X      again: boolean;
  728. X   begin
  729. X      again := true;
  730. X      while again do
  731. X        begin read(prd,ch);(* first character of line*)
  732. X          case ch of
  733. X               'i': readln(prd);
  734. X               'l': begin read(prd,x);
  735. X                  if not eoln(prd) then read(prd,ch);
  736. X                  if ch='=' then read(prd,labelvalue)
  737. X                        else labelvalue:= pc;
  738. X                  update(x); readln(prd);
  739. X                end;
  740. X               'q': begin again := false; readln(prd) end;
  741. X               ' ': begin read(prd,ch); assemble end
  742. X          end;
  743. X        end
  744. X   end; (*generate*)
  745. X
  746. X   procedure assemble; (*translate symbolic code into machine code and store*)
  747. X      label 1;     (*goto 1 for instructions without code generation*)
  748. X      var name :alfa;  b :boolean;  r :real;  s :settype;
  749. X      c1 :char;  i,s1,lb,ub :integer;
  750. X
  751. X      procedure lookup(x: labelrg); (* search in label table*)
  752. X      begin case labeltab[x].st of
  753. X        entered: begin q := labeltab[x].val;
  754. X               labeltab[x].val := pc
  755. X             end;
  756. X        defined: q:= labeltab[x].val
  757. X        end(*case label..*)
  758. X      end;(*lookup*)
  759. X
  760. X      procedure labelsearch;
  761. X     var x: labelrg;
  762. X      begin while (ch<>'l') and not eoln(prd) do read(prd,ch);
  763. X        read(prd,x); lookup(x)
  764. X      end;(*labelsearch*)
  765. X
  766. X      procedure getname;
  767. X      begin  word[1] := ch;
  768. X     read(prd,word[2],word[3]);
  769. X     if not eoln(prd) then read(prd,ch) (*next character*);
  770. X     pack(word,1,name)
  771. X      end; (*getname*)
  772. X
  773. X      procedure typesymbol;
  774. X    var i: integer;
  775. X      begin
  776. X    if ch <> 'i' then
  777. X      begin
  778. X        case ch of
  779. X          'a': i := 0;
  780. X          'r': i := 1;
  781. X          's': i := 2;
  782. X          'b': i := 3;
  783. X          'c': i := 4;
  784. X        end;
  785. X        op := cop[op]+i;
  786. X      end;
  787. X      end (*typesymbol*) ;
  788. X
  789. X   begin  p := 0;  q := 0;  op := 0;
  790. X      getname;
  791. X      instr[duminst] := name;
  792. X      while instr[op]<>name do op := op+1;
  793. X      if op = duminst then errorl(' illegal instruction     ');
  794. X
  795. X      case op of  (* get parameters p,q *)
  796. X
  797. X      (*equ,neq,geq,grt,leq,les*)
  798. X      17,18,19,
  799. X      20,21,22: begin case ch of
  800. X                  'a': ; (*p = 0*)
  801. X                  'i': p := 1;
  802. X                  'r': p := 2;
  803. X                  'b': p := 3;
  804. X                  's': p := 4;
  805. X                  'c': p := 6;
  806. X                  'm': begin p := 5;
  807. X                     read(prd,q)
  808. X                   end
  809. X              end
  810. X            end;
  811. X
  812. X      (*lod,str*)
  813. X      0,2: begin typesymbol; read(prd,p,q)
  814. X           end;
  815. X
  816. X      4  (*lda*): read(prd,p,q);
  817. X
  818. X      12 (*cup*): begin read(prd,p); labelsearch end;
  819. X
  820. X      11 (*mst*): read(prd,p);
  821. X
  822. X      14 (*ret*): case ch of
  823. X                'p': p:=0;
  824. X                'i': p:=1;
  825. X                'r': p:=2;
  826. X                'c': p:=3;
  827. X                'b': p:=4;
  828. X                'a': p:=5
  829. X              end;
  830. X
  831. X      (*lao,ixa,mov*)
  832. X      5,16,55: read(prd,q);
  833. X
  834. X      (*ldo,sro,ind,inc,dec*)
  835. X      1,3,9,10,57: begin typesymbol; read(prd,q)
  836. X               end;
  837. X
  838. X      (*ujp,fjp,xjp*)
  839. X      23,24,25: labelsearch;
  840. X
  841. X      13 (*ent*): begin read(prd,p); labelsearch end;
  842. X
  843. X      15 (*csp*): begin for i:=1 to 9 do read(prd,ch); getname;
  844. X               while name<>sptable[q] do  q := q+1
  845. X              end;
  846. X
  847. X      7 (*ldc*): begin case ch of  (*get q*)
  848. X               'i': begin  p := 1;  read(prd,i);
  849. X                   if abs(i)>=largeint then
  850. X                   begin  op := 8;
  851. X                      store[icp].vi := i;  q := maxstk;
  852. X                      repeat  q := q+1  until store[q].vi=i;
  853. X                      if q=icp then
  854. X                      begin  icp := icp+1;
  855. X                    if icp=overi then
  856. X                      errorl(' integer table overflow  ');
  857. X                      end
  858. X                   end  else q := i
  859. X                end;
  860. X
  861. X               'r': begin  op := 8; p := 2;
  862. X                   read(prd,r);
  863. X                   store[rcp].vr := r;  q := overi;
  864. X                   repeat  q := q+1  until store[q].vr=r;
  865. X                   if q=rcp then
  866. X                   begin  rcp := rcp+1;
  867. X                     if rcp = overr then
  868. X                       errorl(' real table overflow     ');
  869. X                   end
  870. X                end;
  871. X
  872. X               'n': ; (*p,q = 0*)
  873. X
  874. X               'b': begin p := 3;  read(prd,q)  end;
  875. X
  876. X               'c': begin p := 6;
  877. X                  repeat read(prd,ch); until ch <> ' ';
  878. X                  if ch <> '''' then
  879. X                    errorl(' illegal character       ');
  880. X                  read(prd,ch);  q := ord(ch);
  881. X                  read(prd,ch);
  882. X                  if ch <> '''' then
  883. X                    errorl(' illegal character       ');
  884. X                end;
  885. X               '(': begin  op := 8;  p := 4;
  886. X                   s := [ ];  read(prd,ch);
  887. X                   while ch<>')' do
  888. X                   begin read(prd,s1,ch); s := s + [s1]
  889. X                   end;
  890. X                   store[scp].vs := s;  q := overr;
  891. X                   repeat  q := q+1  until store[q].vs=s;
  892. X                   if q=scp then
  893. X                   begin  scp := scp+1;
  894. X                      if scp=overs then
  895. X                    errorl(' set table overflow      ');
  896. X                   end
  897. X                end
  898. X               end (*case*)
  899. X             end;
  900. X
  901. X       26 (*chk*): begin typesymbol;
  902. X             read(prd,lb,ub);
  903. X             if op = 95 then q := lb
  904. X             else
  905. X             begin
  906. X               store[bcp-1].vi := lb; store[bcp].vi := ub;
  907. X               q := overs;
  908. X               repeat  q := q+2
  909. X               until (store[q-1].vi=lb)and (store[q].vi=ub);
  910. X               if q=bcp then
  911. X               begin  bcp := bcp+2;
  912. X                  if bcp=overb then
  913. X                errorl(' boundary table overflow ');
  914. X               end
  915. X             end
  916. X               end;
  917. X
  918. X       56 (*lca*): begin
  919. X             if mcp + 16 >= overm then
  920. X               errorl(' multiple table overflow ');
  921. X             mcp := mcp+16;
  922. X             q := mcp;
  923. X             for i := 0 to 15 (*stringlgth*) do
  924. X             begin read(prd,ch);
  925. X               store[q+i].vc := ch
  926. X             end;
  927. X               end;
  928. X
  929. X      6 (*sto*): typesymbol;
  930. X
  931. X      27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
  932. X      48,49,50,51,52,53,54,58:  ;
  933. X
  934. X      (*ord,chr*)
  935. X      59,60: goto 1;
  936. X
  937. X      61 (*ujc*): ; (*must have same length as ujp*)
  938. X
  939. X      end; (*case*)
  940. X
  941. X      (* store instruction *)
  942. X      with code[pc div 2] do
  943. X     if odd(pc) then
  944. X     begin  op2 := op; p2 := p; q2 := q
  945. X     end  else
  946. X     begin  op1 := op; p1 := p; q1 := q
  947. X     end;
  948. X      pc := pc+1;
  949. X      1: readln(prd);
  950. X   end; (*assemble*)
  951. X
  952. begin (*load*)
  953. X   init;
  954. X   generate;
  955. X   pc := 0;
  956. X   generate;
  957. end; (*load*)
  958. X
  959. (*------------------------------------------------------------------------*)
  960. X
  961. procedure pmd;
  962. X   var s :integer; i: integer;
  963. X
  964. X   procedure pt;
  965. X   begin  write(s:6);
  966. X      if abs(store[s].vi) < maxint then write(store[s].vi)
  967. X      else write('too big ');
  968. X      s := s - 1;
  969. X      i := i + 1;
  970. X      if i = 4 then
  971. X     begin writeln(output); i := 0 end;
  972. X   end; (*pt*)
  973. X
  974. begin
  975. X   write(' pc =',pc-1:5,' op =',op:3,'  sp =',sp:5,'  mp =',mp:5,
  976. X    '  np =',np:5);
  977. X   writeln; writeln('--------------------------------------');
  978. X
  979. X   s := sp; i := 0;
  980. X   while s>=0 do pt;
  981. X   s := maxstk;
  982. X   while s>=np do pt;
  983. end; (*pmd*)
  984. X
  985. procedure errori(string: beta);
  986. begin writeln; writeln(string);
  987. X      pmd; goto 1
  988. end;(*errori*)
  989. X
  990. function base(ld :integer):address;
  991. X   var ad :address;
  992. begin  ad := mp;
  993. X   while ld>0 do
  994. X   begin  ad := store[ad+1].vm;  ld := ld-1
  995. X   end;
  996. X   base := ad
  997. end; (*base*)
  998. X
  999. procedure compare;
  1000. (*comparing is only correct if result by comparing integers will be*)
  1001. begin
  1002. X  i1 := store[sp].va;
  1003. X  i2 := store[sp+1].va;
  1004. X  i := 0; b := true;
  1005. X  while b and (i<>q) do
  1006. X    if store[i1+i].vi = store[i2+i].vi then i := i+1
  1007. X    else b := false
  1008. end; (*compare*)
  1009. X
  1010. procedure callsp;
  1011. X   var line: boolean; adptr,adelnt: address;
  1012. X       i: integer;
  1013. X
  1014. X   procedure readi(var f:text);
  1015. X      var ad: address;
  1016. X   begin ad:= store[sp-1].va;
  1017. X     read(f,store[ad].vi);
  1018. X     store[store[sp].va].vc := f^;
  1019. X     sp:= sp-2
  1020. X   end;(*readi*)
  1021. X
  1022. X   procedure readr(var f: text);
  1023. X      var ad: address;
  1024. X   begin ad:= store[sp-1].va;
  1025. X     read(f,store[ad].vr);
  1026. X     store[store[sp].va].vc := f^;
  1027. X     sp:= sp-2
  1028. X   end;(*readr*)
  1029. X
  1030. X   procedure readc(var f: text);
  1031. X      var c: char; ad: address;
  1032. X   begin read(f,c);
  1033. X     ad:= store[sp-1].va;
  1034. X     store[ad].vc := c;
  1035. X     store[store[sp].va].vc := f^;
  1036. X     store[store[sp].va].vi := ord(f^);
  1037. X     sp:= sp-2
  1038. X   end;(*readc*)
  1039. X
  1040. X   procedure writestr(var f: text);
  1041. X      var i,j,k: integer;
  1042. X      ad: address;
  1043. X   begin ad:= store[sp-3].va;
  1044. X     k := store[sp-2].vi; j := store[sp-1].vi;
  1045. X     (* j and k are numbers of characters *)
  1046. X     if k>j then for i:=1 to k-j do write(f,' ')
  1047. X        else j:= k;
  1048. X     for i := 0 to j-1 do write(f,store[ad+i].vc);
  1049. X     sp:= sp-4
  1050. X   end;(*writestr*)
  1051. X
  1052. X   procedure getfile(var f: text);
  1053. X      var ad: address;
  1054. X   begin ad:=store[sp].va;
  1055. X     get(f); store[ad].vc := f^;
  1056. X     sp:=sp-1
  1057. X   end;(*getfile*)
  1058. X
  1059. X   procedure putfile(var f: text);
  1060. X      var ad: address;
  1061. X   begin ad:= store[sp].va;
  1062. X     f^:= store[ad].vc; put(f);
  1063. X     sp:= sp-1;
  1064. X   end;(*putfile*)
  1065. X
  1066. begin (*callsp*)
  1067. X      case q of
  1068. X       0 (*get*): case store[sp].va of
  1069. X               5: getfile(input);
  1070. X               6: errori(' get on output file      ');
  1071. X               7: getfile(prd);
  1072. X               8: errori(' get on prr file     ')
  1073. X              end;
  1074. X       1 (*put*): case store[sp].va of
  1075. X               5: errori(' put on read file    ');
  1076. X               6: putfile(output);
  1077. X               7: errori(' put on prd file     ');
  1078. X               8: putfile(prr)
  1079. X              end;
  1080. X       2 (*rst*): begin
  1081. X            (*for testphase*)
  1082. X            np := store[sp].va; sp := sp-1
  1083. X              end;
  1084. X       3 (*rln*): begin case store[sp].va of
  1085. X                 5: begin readln(input);
  1086. X                      store[inputadr].vc := input^
  1087. X                    end;
  1088. X                 6: errori(' readln on output file   ');
  1089. X                 7: begin readln(input);
  1090. X                      store[inputadr].vc := input^
  1091. X                    end;
  1092. X                 8: errori(' readln on prr file      ')
  1093. X                end;
  1094. X                sp:= sp-1
  1095. X              end;
  1096. X       4 (*new*): begin ad:= np-store[sp].va;
  1097. X              (*top of stack gives the length in units of storage *)
  1098. X                if ad <= ep then
  1099. X                  errori(' store overflow      ');
  1100. X                np:= ad; ad:= store[sp-1].va;
  1101. X                store[ad].va := np;
  1102. X                sp:=sp-2
  1103. X              end;
  1104. X       5 (*wln*): begin case store[sp].va of
  1105. X                 5: errori(' writeln on input file   ');
  1106. X                 6: writeln(output);
  1107. X                 7: errori(' writeln on prd file     ');
  1108. X                 8: writeln(prr)
  1109. X                end;
  1110. X                sp:= sp-1
  1111. X              end;
  1112. X       6 (*wrs*): case store[sp].va of
  1113. X               5: errori(' write on input file     ');
  1114. X               6: writestr(output);
  1115. X               7: errori(' write on prd file       ');
  1116. X               8: writestr(prr)
  1117. X              end;
  1118. X       7 (*eln*): begin case store[sp].va of
  1119. X                 5: line:= eoln(input);
  1120. X                 6: errori(' eoln output file    ');
  1121. X                 7: line:=eoln(prd);
  1122. X                 8: errori(' eoln on prr file    ')
  1123. X                end;
  1124. X                store[sp].vb := line
  1125. X              end;
  1126. X       8 (*wri*): begin case store[sp].va of
  1127. X                 5: errori(' write on input file     ');
  1128. X                 6: write(output,
  1129. X                      store[sp-2].vi: store[sp-1].vi);
  1130. X                 7: errori(' write on prd file       ');
  1131. X                 8: write(prr,
  1132. X                      store[sp-2].vi: store[sp-1].vi)
  1133. X                end;
  1134. X                sp:=sp-3
  1135. X              end;
  1136. X       9 (*wrr*): begin case store[sp].va of
  1137. X                 5: errori(' write on input file     ');
  1138. X                 6: write(output,
  1139. X                      store[sp-2].vr: store[sp-1].vi);
  1140. X                 7: errori(' write on prd file       ');
  1141. X                 8: write(prr,
  1142. X                      store[sp-2].vr: store[sp-1].vi)
  1143. X                end;
  1144. X                sp:=sp-3
  1145. X              end;
  1146. X       10(*wrc*): begin case store[sp].va of
  1147. X                 5: errori(' write on input file     ');
  1148. X                 6: write(output,store[sp-2].vc:
  1149. X                      store[sp-1].vi);
  1150. X                 7: errori(' write on prd file       ');
  1151. X                 8: write(prr,chr(store[sp-2].vi):
  1152. X                      store[sp-1].vi);
  1153. X                end;
  1154. X                sp:=sp-3
  1155. X              end;
  1156. X       11(*rdi*): case store[sp].va of
  1157. X               5: readi(input);
  1158. X               6: errori(' read on output file     ');
  1159. X               7: readi(prd);
  1160. X               8: errori(' read on prr file    ')
  1161. X              end;
  1162. X       12(*rdr*): case store[sp].va of
  1163. X               5: readr(input);
  1164. X               6: errori(' read on output file     ');
  1165. X               7: readr(prd);
  1166. X               8: errori(' read on prr file    ')
  1167. X              end;
  1168. X       13(*rdc*): case store[sp].va of
  1169. X               5: readc(input);
  1170. X               6: errori(' read on output file     ');
  1171. X               7: readc(prd);
  1172. X               8: errori(' read on prr file    ')
  1173. X              end;
  1174. X       14(*sin*): store[sp].vr:= sin(store[sp].vr);
  1175. X       15(*cos*): store[sp].vr:= cos(store[sp].vr);
  1176. X       16(*exp*): store[sp].vr:= exp(store[sp].vr);
  1177. X       17(*log*): store[sp].vr:= ln(store[sp].vr);
  1178. X       18(*sqt*): store[sp].vr:= sqrt(store[sp].vr);
  1179. X       19(*atn*): store[sp].vr:= arctan(store[sp].vr);
  1180. X       20(*sav*): begin ad:=store[sp].va;
  1181. X             store[ad].va := np;
  1182. X             sp:= sp-1
  1183. X              end;
  1184. X      end;(*case q*)
  1185. end;(*callsp*)
  1186. X
  1187. begin (* main *)
  1188. X  rewrite(prr);
  1189. X  load; (* assembles and stores code *)
  1190. X  writeln(output); (* for testing *)
  1191. X  pc := 0; sp := -1; mp := 0; np := maxstk+1; ep := 5;
  1192. X  store[inputadr].vc := input^;
  1193. X  store[prdadr].vc := prd^;
  1194. X  interpreting := true;
  1195. X
  1196. X  while interpreting do
  1197. X  begin
  1198. X    (*fetch*)
  1199. X    with code[pc div 2] do
  1200. X      if odd(pc) then
  1201. X      begin op := op2; p := p2; q := q2
  1202. X      end else
  1203. X      begin op := op1; p := p1; q := q1
  1204. X      end;
  1205. X    pc := pc+1;
  1206. X
  1207. X    (*execute*)
  1208. X    case op of
  1209. X
  1210. X      105,106,107,108,109,
  1211. X      0 (*lod*): begin  ad := base(p) + q;
  1212. X              sp := sp+1;
  1213. X              store[sp] := store[ad]
  1214. X             end;
  1215. X
  1216. X      65,66,67,68,69,
  1217. X      1 (*ldo*): begin
  1218. X              sp := sp+1;
  1219. X              store[sp] := store[q]
  1220. X             end;
  1221. X
  1222. X      70,71,72,73,74,
  1223. X      2 (*str*): begin  store[base(p)+q] := store[sp];
  1224. X              sp := sp-1
  1225. X             end;
  1226. X
  1227. X      75,76,77,78,79,
  1228. X      3 (*sro*): begin  store[q] := store[sp];
  1229. X              sp := sp-1
  1230. X             end;
  1231. X
  1232. X      4 (*lda*): begin sp := sp+1;
  1233. X              store[sp].va := base(p) + q
  1234. X             end;
  1235. X
  1236. X      5 (*lao*): begin sp := sp+1;
  1237. X              store[sp].va := q
  1238. X             end;
  1239. X
  1240. X      80,81,82,83,84,
  1241. X      6 (*sto*): begin
  1242. X              store[store[sp-1].va] := store[sp];
  1243. X              sp := sp-2;
  1244. X             end;
  1245. X
  1246. X      7 (*ldc*): begin sp := sp+1;
  1247. X              if p=1 then
  1248. X              begin store[sp].vi := q;
  1249. X              end else
  1250. X              if p = 6 then store[sp].vc := chr(q)
  1251. X              else
  1252. X                if p = 3 then store[sp].vb := q = 1
  1253. X                else (* load nil *) store[sp].va := maxstr
  1254. X             end;
  1255. X
  1256. X      8 (*lci*): begin sp := sp+1;
  1257. X              store[sp] := store[q]
  1258. X             end;
  1259. X
  1260. X      85,86,87,88,89,
  1261. X      9 (*ind*): begin ad := store[sp].va + q;
  1262. X              (* q is a number of storage units *)
  1263. X              store[sp] := store[ad]
  1264. X             end;
  1265. X
  1266. X      90,91,92,93,94,
  1267. X      10 (*inc*): store[sp].vi := store[sp].vi+q;
  1268. X
  1269. X      11 (*mst*): begin (*p=level of calling procedure minus level of called
  1270. X                  procedure + 1;  set dl and sl, increment sp*)
  1271. X               (* then length of this element is
  1272. X              max(intsize,realsize,boolsize,charsize,ptrsize *)
  1273. X               store[sp+2].vm := base(p);
  1274. X               (* the length of this element is ptrsize *)
  1275. X               store[sp+3].vm := mp;
  1276. X               (* idem *)
  1277. X               store[sp+4].vm := ep;
  1278. X               (* idem *)
  1279. X               sp := sp+5
  1280. X              end;
  1281. X
  1282. X      12 (*cup*): begin (*p=no of locations for parameters, q=entry point*)
  1283. X               mp := sp-(p+4);
  1284. X               store[mp+4].vm := pc;
  1285. X               pc := q
  1286. X              end;
  1287. X
  1288. X      13 (*ent*): if p = 1 then
  1289. X            begin sp := mp + q; (*q = length of dataseg*)
  1290. X              if sp > np then errori(' store overflow      ');
  1291. X            end
  1292. X              else
  1293. X            begin ep := sp+q;
  1294. X              if ep > np then errori(' store overflow      ');
  1295. X            end;
  1296. X            (*q = max space required on stack*)
  1297. X
  1298. X      14 (*ret*): begin case p of
  1299. X                 0: sp:= mp-1;
  1300. X                 1,2,3,4,5: sp:= mp
  1301. X                end;
  1302. X                pc := store[mp+4].vm;
  1303. X                ep := store[mp+3].vm;
  1304. X                mp:= store[mp+2].vm;
  1305. X              end;
  1306. X
  1307. X      15 (*csp*): callsp;
  1308. X
  1309. X      16 (*ixa*): begin
  1310. X               i := store[sp].vi;
  1311. X               sp := sp-1;
  1312. X               store[sp].va := q*i+store[sp].va;
  1313. X              end;
  1314. X
  1315. X      17 (*equ*): begin  sp := sp-1;
  1316. X               case p of
  1317. X             1: store[sp].vb := store[sp].vi = store[sp+1].vi;
  1318. X             0: store[sp].vb := store[sp].va = store[sp+1].va;
  1319. X             6: store[sp].vb := store[sp].vc = store[sp+1].vc;
  1320. X             2: store[sp].vb := store[sp].vr = store[sp+1].vr;
  1321. X             3: store[sp].vb := store[sp].vb = store[sp+1].vb;
  1322. X             4: store[sp].vb := store[sp].vs = store[sp+1].vs;
  1323. X             5: begin  compare;
  1324. X                   store[sp].vb := b;
  1325. X                end;
  1326. X               end; (*case p*)
  1327. X              end;
  1328. X
  1329. X      18 (*neq*): begin  sp := sp-1;
  1330. X               case p of
  1331. X             0: store[sp].vb := store[sp].va <> store[sp+1].va;
  1332. X             1: store[sp].vb := store[sp].vi <> store[sp+1].vi;
  1333. X             6: store[sp].vb := store[sp].vc <> store[sp+1].vc;
  1334. X             2: store[sp].vb := store[sp].vr <> store[sp+1].vr;
  1335. X             3: store[sp].vb := store[sp].vb <> store[sp+1].vb;
  1336. X             4: store[sp].vb := store[sp].vs <> store[sp+1].vs;
  1337. X             5: begin  compare;
  1338. X                   store[sp].vb := not b;
  1339. X                end
  1340. X               end; (*case p*)
  1341. X              end;
  1342. X
  1343. X      19 (*geq*): begin  sp := sp-1;
  1344. X               case p of
  1345. X             0: errori(' <,<=,>,>= for address   ');
  1346. X             1: store[sp].vb := store[sp].vi >= store[sp+1].vi;
  1347. X             6: store[sp].vb := store[sp].vc >= store[sp+1].vc;
  1348. X             2: store[sp].vb := store[sp].vr >= store[sp+1].vr;
  1349. X             3: store[sp].vb := store[sp].vb >= store[sp+1].vb;
  1350. X             4: store[sp].vb := store[sp].vs >= store[sp+1].vs;
  1351. X             5: begin compare;
  1352. X                  store[sp].vb := b or
  1353. X                (store[i1+i].vi >= store[i2+i].vi)
  1354. X                end
  1355. X               end; (*case p*)
  1356. X              end;
  1357. X
  1358. X      20 (*grt*): begin  sp := sp-1;
  1359. X               case p of
  1360. X             0: errori(' <,<=,>,>= for address   ');
  1361. X             1: store[sp].vb := store[sp].vi > store[sp+1].vi;
  1362. X             6: store[sp].vb := store[sp].vc > store[sp+1].vc;
  1363. X             2: store[sp].vb := store[sp].vr > store[sp+1].vr;
  1364. X             3: store[sp].vb := store[sp].vb > store[sp+1].vb;
  1365. X             4: errori(' set inclusion       ');
  1366. X             5: begin  compare;
  1367. X                  store[sp].vb := not b and
  1368. X                (store[i1+i].vi > store[i2+i].vi)
  1369. X                end
  1370. X               end; (*case p*)
  1371. X              end;
  1372. X
  1373. X      21 (*leq*): begin  sp := sp-1;
  1374. X               case p of
  1375. X             0: errori(' <,<=,>,>= for address   ');
  1376. X             1: store[sp].vb := store[sp].vi <= store[sp+1].vi;
  1377. X             6: store[sp].vb := store[sp].vc <= store[sp+1].vc;
  1378. X             2: store[sp].vb := store[sp].vr <= store[sp+1].vr;
  1379. X             3: store[sp].vb := store[sp].vb <= store[sp+1].vb;
  1380. X             4: store[sp].vb := store[sp].vs <= store[sp+1].vs;
  1381. X             5: begin  compare;
  1382. X                  store[sp].vb := b or
  1383. X                (store[i1+i].vi <= store[i2+i].vi)
  1384. X                end;
  1385. X               end; (*case p*)
  1386. X              end;
  1387. X
  1388. X      22 (*les*): begin  sp := sp-1;
  1389. X               case p of
  1390. X             0: errori(' <,<=,>,>= for address   ');
  1391. X             1: store[sp].vb := store[sp].vi < store[sp+1].vi;
  1392. X             6: store[sp].vb := store[sp].vc < store[sp+1].vc;
  1393. X             2: store[sp].vb := store[sp].vr < store[sp+1].vr;
  1394. X             3: store[sp].vb := store[sp].vb < store[sp+1].vb;
  1395. X             5: begin  compare;
  1396. X                  store[sp].vb := not b and
  1397. X                (store[i1+i].vi < store[i2+i].vi)
  1398. X                end
  1399. X               end; (*case p*)
  1400. X              end;
  1401. X
  1402. X      23 (*ujp*): pc := q;
  1403. X
  1404. X      24 (*fjp*): begin  if not store[sp].vb then pc := q;
  1405. X               sp := sp-1
  1406. X              end;
  1407. X
  1408. X      25 (*xjp*): begin
  1409. X               pc := store[sp].vi + q;
  1410. X               sp := sp-1
  1411. X              end;
  1412. X
  1413. X      95 (*chka*): if (store[sp].va < np) or
  1414. X              (store[sp].va > (maxstr-q)) then
  1415. X             errori(' bad pointer value       ');
  1416. X
  1417. X      96,97,98,99,
  1418. X      26 (*chk*): if (store[sp].vi < store[q-1].vi) or
  1419. X             (store[sp].vi > store[q].vi) then
  1420. X            errori(' value out of range      ');
  1421. X
  1422. X      27 (*eof*): begin  i := store[sp].vi;
  1423. X               if i=inputadr then
  1424. X               begin store[sp].vb := eof(input);
  1425. X               end else errori(' code in error       ')
  1426. X              end;
  1427. X
  1428. X      28 (*adi*): begin  sp := sp-1;
  1429. X               store[sp].vi := store[sp].vi + store[sp+1].vi
  1430. X              end;
  1431. X
  1432. X      29 (*adr*): begin  sp := sp-1;
  1433. X               store[sp].vr := store[sp].vr + store[sp+1].vr
  1434. X              end;
  1435. X
  1436. X      30 (*sbi*): begin sp := sp-1;
  1437. X               store[sp].vi := store[sp].vi - store[sp+1].vi
  1438. X              end;
  1439. X
  1440. X      31 (*sbr*): begin  sp := sp-1;
  1441. X               store[sp].vr := store[sp].vr - store[sp+1].vr
  1442. X              end;
  1443. X
  1444. X      32 (*sgs*): store[sp].vs := [store[sp].vi];
  1445. X
  1446. X      33 (*flt*): store[sp].vr := store[sp].vi;
  1447. X
  1448. X      34 (*flo*): store[sp-1].vr := store[sp-1].vi;
  1449. X
  1450. X      35 (*trc*): store[sp].vi := trunc(store[sp].vr);
  1451. X
  1452. X      36 (*ngi*): store[sp].vi := -store[sp].vi;
  1453. X
  1454. X      37 (*ngr*): store[sp].vr := -store[sp].vr;
  1455. X
  1456. X      38 (*sqi*): store[sp].vi := sqr(store[sp].vi);
  1457. X
  1458. X      39 (*sqr*): store[sp].vr := sqr(store[sp].vr);
  1459. X
  1460. X      40 (*abi*): store[sp].vi := abs(store[sp].vi);
  1461. X
  1462. X      41 (*abr*): store[sp].vr := abs(store[sp].vr);
  1463. X
  1464. X      42 (*not*): store[sp].vb := not store[sp].vb;
  1465. X
  1466. X      43 (*and*): begin  sp := sp-1;
  1467. X               store[sp].vb := store[sp].vb and store[sp+1].vb
  1468. X              end;
  1469. X
  1470. X      44 (*ior*): begin  sp := sp-1;
  1471. X               store[sp].vb := store[sp].vb or store[sp+1].vb
  1472. X              end;
  1473. X
  1474. X      45 (*dif*): begin  sp := sp-1;
  1475. X               store[sp].vs := store[sp].vs - store[sp+1].vs
  1476. X              end;
  1477. X
  1478. X      46 (*int*): begin  sp := sp-1;
  1479. X               store[sp].vs := store[sp].vs * store[sp+1].vs
  1480. X              end;
  1481. X
  1482. X      47 (*uni*): begin  sp := sp-1;
  1483. X               store[sp].vs := store[sp].vs + store[sp+1].vs
  1484. X              end;
  1485. X
  1486. X      48 (*inn*): begin
  1487. X               sp := sp - 1; i := store[sp].vi;
  1488. X               store[sp].vb := i in store[sp+1].vs;
  1489. X              end;
  1490. X
  1491. X      49 (*mod*): begin  sp := sp-1;
  1492. X               store[sp].vi := store[sp].vi mod store[sp+1].vi
  1493. X              end;
  1494. X
  1495. X      50 (*odd*): store[sp].vb := odd(store[sp].vi);
  1496. X
  1497. X      51 (*mpi*): begin  sp := sp-1;
  1498. X               store[sp].vi := store[sp].vi * store[sp+1].vi
  1499. X              end;
  1500. X
  1501. X      52 (*mpr*): begin  sp := sp-1;
  1502. X               store[sp].vr := store[sp].vr * store[sp+1].vr
  1503. X              end;
  1504. X
  1505. X      53 (*dvi*): begin  sp := sp-1;
  1506. X               store[sp].vi := store[sp].vi div store[sp+1].vi
  1507. X              end;
  1508. X
  1509. X      54 (*dvr*): begin  sp := sp-1;
  1510. X               store[sp].vr := store[sp].vr / store[sp+1].vr
  1511. X              end;
  1512. X
  1513. X      55 (*mov*): begin i1 := store[sp-1].va;
  1514. X               i2 := store[sp].va; sp := sp-2;
  1515. X               for i := 0 to q-1 do store[i1+i] := store[i2+i]
  1516. X               (* q is a number of storage units *)
  1517. X              end;
  1518. X
  1519. X      56 (*lca*): begin  sp := sp+1;
  1520. X               store[sp].va := q;
  1521. X              end;
  1522. X
  1523. X      100,101,102,103,104,
  1524. X      57 (*dec*): store[sp].vi := store[sp].vi-q;
  1525. X
  1526. X      58 (*stp*): interpreting := false;
  1527. X
  1528. X      59 (*ord*): (*only used to change the tagfield*)
  1529. X              begin
  1530. X              end;
  1531. X
  1532. X      60 (*chr*): begin
  1533. X              end;
  1534. X
  1535. X      61 (*ujc*): errori(' case - error        ');
  1536. X    end
  1537. X  end; (*while interpreting*)
  1538. X
  1539. 1 :
  1540. end.
  1541. SHAR_EOF
  1542. chmod 0644 pint.p ||
  1543. echo 'restore of pint.p failed'
  1544. Wc_c="`wc -c < 'pint.p'`"
  1545. test 28139 -eq "$Wc_c" ||
  1546.     echo 'pint.p: original size 28139, current size' "$Wc_c"
  1547. rm -f _shar_wnt_.tmp
  1548. fi
  1549. rm -f _shar_seq_.tmp
  1550. echo You have unpacked the last part
  1551. exit 0
  1552. exit 0 # Just in case...
  1553. -- 
  1554. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1555. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1556. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1557. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1558.  
  1559.